package chat.aylan.top.database.service;
/**
 * 数据连接器
 */

import chat.aylan.top.commons.Constants;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class MysqlConnector {

    private static MysqlConnector connector;

    Connection connection;

    private MysqlConnector(){
        try {
            Class.forName("com.mysql.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }

    public static MysqlConnector getConnection(){

        if(connector == null){
           connector = new MysqlConnector();
        }
        try {
            connector.connection = DriverManager.getConnection(Constants.MYSQL_URL,Constants.MYSQL_USER,Constants.MYSQL_PASSWORD);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return connector;
    }
}
